package rsj.dao;

import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import rsj.db.PostgreExecutor;
import rsj.domain.ProductTypePo;
import rsj.util.EntityUtils;

import java.util.List;
import java.util.Map;

public class PrtyDao extends BaseDao {
    private static final PrtyDao instance = new PrtyDao();
    public static PrtyDao getInstance() {
        return instance;
    }
    private static final String table_name = "sys.sys_prty";
    private static final String columns_all = "prty_fid,prty_fname,prty_sid,prty_sname";


    public List<ProductTypePo> getTwoType() {
        return (List<ProductTypePo>) PostgreExecutor.invokeSql(conn -> {
            TableNode tableNode = getQueryRunner().queryLinkTableNode(conn, String.format(selectWithoutWhere, columns_all, table_name));
            List<Map<String,Object>> results = tableNode.toList();
            return EntityUtils.listMapToListObject(results, ProductTypePo.class);
        });
    }

    public List<ProductTypePo> getOneType() {
        return (List<ProductTypePo>) PostgreExecutor.invokeSql(conn -> {
            TableNode tableNode = getQueryRunner().queryLinkTableNode(conn, "select prty_fid,prty_fname from sys.sys_prty \n" +
                    "group by prty_fid,prty_fname");
            List<Map<String,Object>> results = tableNode.toList();
            return EntityUtils.listMapToListObject(results, ProductTypePo.class);
        });
    }

    public MapNode getBySid(String prod_type_sid) {
        return (MapNode) invokeSql(conn -> {
           String sql = String.format(select, columns_all, table_name, " prty_sid = ? ");
           return getQueryRunner().queryLinkRow(conn, sql, prod_type_sid);
        });
    }
}
